package cn.zswltech.gruul.web.api.util;

import java.nio.charset.Charset;

/**
 * @author Jason
 * @version 1.0.0
 */
public class RSAKeyUtils {

    public static String decryptByPublicKey(String entryData, String publicKey) throws Exception {
        //解密
        return new String(RSAUtils.decryptByPublicKey(Base64Utils.decode(entryData), publicKey), Charset.defaultCharset());
    }

    private static String handleKey(String key) {
        return key.substring(key.indexOf("\n"), key.lastIndexOf(("\n"))).replaceAll("\t", "");
    }

    public static void main(String[] args) throws Exception {
        String publicKey = "-----BEGIN PUBLIC KEY-----\n" +
                "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDt05mqd4TYLPwahcRnM8woZI1Q\n" +
                "4+vTcTEIm1Cvvgi7FxPO+z4I7MeeTJCqqxzxEeZk5e1QgnkcKInRZAdVmlRT3Hux\n" +
                "x2guh3YAzhj2Y4sSsdNTqvJwKm+WGlVifGu1hTQ7wwvnf5cYZo5f1Fj17SDCR+kl\n" +
                "Y/FLLSEMl1UZ/5EF6wIDAQAB\n" +
                "-----END PUBLIC KEY-----";
        //解密
        String entryData = "iSDPgo9II61hA85c8o0DdwgLX1TDJRqxVyaVQ6vPRN1KL6eG/25lsNxWq1w/JJDhA2+T49hUjwpZl+lz8CEUI1RmS/ExpOtll4MXjbCMU9BWjmUBhOHxCzzbH0eWMOA2T0RdUVJVTIRVQwlIURqoRnd8VZPg33LAITEwpVY1fa5F6iB4hepknRd3PVFFFXOtWX03AtUe2s3mcuv0wSPvwQAzLrx26O7xHuOHsP0/Eml0hsKO+4QV+BftyiaTaxY/XWPMyhGotdlKQNPzOJ0BHqdbNYrTxn43voFqgcwlNnBqxpKx5HqxNCkZ+u/N4vrXp+wnfxwnRmzhPZkXyNEfc2Qfc7QtlnY+P+9wIe8TIppkbjj+NerP/PTVX0DTmvX873Tm2bu3tszzga6hCin9yPBMC5ktLRs6zj4BS0yz2w/thwQalHfJfbHQZ6CJxaddFewZU/r7qdb8z58mXcY1wcBXDUuC+Pw6IgG2kcP0LbMCef23rzZbnUTO/zeQQ2WW";
        String data = RSAKeyUtils.decryptByPublicKey(entryData, publicKey);
        System.out.println("明文:\n" + data);
    }
}
